﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace FourthWallProject.GameObjects.Screens
{
    class MessageBoxScreen : GameScreen
    {
        Texture2D _background;

        public Texture2D Background
        {
            get { return _background; }
            set { _background = value; }
        }
        
        string _text;

        public string Text
        {
            get { return _text; }
            set { _text = value; }
        }

        static Random rand = new Random();
        public MessageBoxScreen(Game game, string Text)
            : base(game)
        {
            this.Text = Text;
            this.Background = Game.Content.Load<Texture2D>("Images/MessageBox");
            base.Initialize();
             x = rand.Next(1, 800);
             y = rand.Next(1, 500);
        }

        DateTime _endTime;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="game"></param>
        /// <param name="Text"></param>
        /// <param name="Duration">null for indefinite time</param>
        public MessageBoxScreen(Game game,string Text, TimeSpan Duration)
            : this (game,Text)
        {
            if (Duration != null)
            {
                _endTime = DateTime.Now + Duration;
            }
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (DateTime.Now > _endTime)
                ScreenManager.RemoveScreen(this);
        }

        int x;
        int y;
        public override void Draw(GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {

            spriteBatch.Begin();
            spriteBatch.Draw(Background, new Rectangle(x,y,100,100), new Color(){R=100,G=100,B=100,A=100});
            spriteBatch.DrawString(GameState.MenuFont, Text, new Vector2(x+10, y+10), Color.Black);
            spriteBatch.End();
            base.Draw(gameTime, spriteBatch);
        }
    }
}
